package com.example.yucheng.mapper;

import com.example.yucheng.domain.Category;
import com.example.yucheng.util.PageQuery;
import org.apache.ibatis.annotations.*;

import java.util.List;

//分类数据访问层
@Mapper
public interface CategoryMapper {

    @Select("SELECT * from category")
    public List<Category> getAllCategory();

    @Select("SELECT * FROM category order by time desc limit #{pageNum},#{pageSize}")
    public List<Category> getCategoryByLimit(PageQuery pageQuery);

    @Select("SELECT * FROM category order by time asc limit #{pageNum},#{pageSize}")
    public List<Category> ascgetCategoryByLimit(PageQuery pageQuery);

    @Delete("DELETE FROM category WHERE id = #{id}")
    public int deleteCategoryById(@Param("id") Integer id);

    @Insert("INSERT INTO category (name,description,remark,time) VALUES(#{name},#{description},#{remark},NOW())")
    public int insertCategory(Category category);

    @Update("UPDATE category SET name = #{name},description = #{description},remark=#{remark} WHERE id = #{id}")
    public int updateCategory(Category category);

    @Select("SELECT name FROM category where name = #{name}")
    public String selectCategoryName(String name);
}
